const router = require("koa-router")();
const Mock = require("mockjs");
const { list } = Mock.mock({
  "list|100": [
    {
      id: "@id",
      image: "@image(150x120, @color)",
      title: "@ctitle",
      word: "@cword(10, 20)",
      "type|1": [
        "万达",
        "博纳国际",
        "成龙国际",
        "包里国际",
        "大地影院",
        "完美世界",
        "首都世界",
      ],
    },
  ],
});
router.get("/list", (ctx) => {
  const { type, q } = ctx.request.query;
  let filterList = [...list];

  if (type) {
    filterList = filterList.filter((v) => v.type === type);
  }

  if (q) {
    filterList = filterList.filter((v) => JSON.stringify(v).includes(q));
  }

  ctx.body = {
    code: 200,
    data: filterList,
  };
});
module.exports = router;

